<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <!-- 计算属性：computed  属性的调用  有缓存  一个值依赖多个值
    
        methods 函数调用  没有缓存

        watch:监听  一个值影响多个值
    
    -->

    <!-- let obj = {reverseStr:function(){return }} -->
    <div id="app">
        {{msg.split('').reverse().join('')}}
        <br>
        {{reverseStr}}
        {{reverseStr}}
        {{reverseStr}}
        {{reverseStr}}
        <br>
        {{mReverseStr()}}
        {{mReverseStr()}}
        {{mReverseStr()}}
        {{mReverseStr()}}
        <br>
        watch:
        {{reStr}}

        <ul>
            <li v-for="item in list">
                {{item.name}} ---- {{like(item.like)}}
            </li>
        </ul>

        地址：{{address}}
    </div>
    <script src="./vue.js"></script>
    <script>
        let vm = new Vue({
            el:'#app',
            data:{
                msg:'hello vue',
                reStr:'',
                list:[
                    {
                        name:'小红',
                        like:[1,2,3]
                    },
                    {
                        name:'小明',
                        like:[2,3]
                    },
                    {
                        name:'小兰',
                        like:[1,3]
                    }
                ],
                obj:{
                    1:'打羽毛球',
                    2:'打篮球',
                    3:'踢足球'
                },
                privice:'河北省',
                city:'石家庄市'
            },
            computed:{
                reverseStr(){
                    // console.log("---reverseStr---")
                    return this.msg.split('').reverse().join('')
                },
                // address(){
                //     return this.privice + this.city
                // },
                address:{
                    // console.log("address")
                    // return this.privice + this.city

                    set(val){
                        console.log(val);
                        this.privice = val.split('-')[0];
                        this.city =  val.split('-')[1];
                    },
                    get(){
                        return this.privice +'-'+ this.city
                    }
                }
            },
            methods:{
                mReverseStr(){
                    console.log("---mReverseStr---")
                    return this.msg.split('').reverse().join('')
                },
                like(arr){
                    return arr.map(item => this.obj[item]).join('-')
                }
            },
            watch:{
                msg(newVal,oldVal){
                    console.log(newVal,oldVal);
                    this.reStr = newVal.split('').reverse().join('');
                }
            }
        })
    </script>
</body>
</html>